package sword.T30;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @Author: duyuzhou
 * @Create: 2022-04-07 15:53:06 星期四
 */

class MinStack {

    class Node {
        int minValue;
        int value;

        Node(int value, int minValue) {
            this.value = value;
            this.minValue = minValue;
        }
    }

    private Deque<Node> stack = new LinkedList<>();

    /** initialize your data structure here. */
    public MinStack() {

    }

    public void push(int x) {
        int minValue = 0;
        if (stack.isEmpty()) {
            minValue = x;
        }
        else {
            minValue = Math.min(x, stack.peek().minValue);
        }
        stack.push(new Node(x, minValue));
    }

    public void pop() {
        stack.pop();
    }

    public int top() {
        return stack.peek().value;
    }

    public int min() {
        return stack.peek().minValue;
    }
}

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack obj = new MinStack();
 * obj.push(x);
 * obj.pop();
 * int param_3 = obj.top();
 * int param_4 = obj.min();
 */